package cz.fit.vutbr.pis2012.augeaswh.managers;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import cz.fit.vutbr.pis2012.augeaswh.persistence.Slot;

@Stateless
public class SlotsManager {
	@PersistenceContext
	private EntityManager em;
	
	@SuppressWarnings("unchecked")
	public List<Slot> getSlots() {
		return	em.createQuery("SELECT s FROM Slot s").getResultList();
	}
	
	public void save(Slot slot) {
		em.merge(slot);			
	}
	
	public void delete(Slot slot) {
	    em.remove(em.merge(slot));
	}
	
	public Slot getSlotById(Long id) {
		@SuppressWarnings("unchecked")
		Slot slot = (Slot) em.createQuery("SELECT s FROM Slot s WHERE s.id = :id").setParameter("id", id).getSingleResult();
		return slot;
	}
}
